package com.quartet.modules.statistics.controller;


import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.quartet.api.ApiResult;
import com.quartet.api.PageResult;
import com.quartet.modules.customer.dto.TCustomerInfoResponseDto;
import com.quartet.modules.customer.entity.TCustomerInfo;
import com.quartet.modules.customer.service.TCustomerInfoService;
import com.quartet.modules.multimedia.dao.TMultimediaDao;
import com.quartet.modules.multimedia.dto.MediaCountResponseDto;
import com.quartet.modules.statistics.dto.*;
import com.quartet.modules.stock.dao.TTerminalStockDao;
import com.quartet.modules.stock.dto.TTerminalCountGroupByCustomerDto;
import com.quartet.modules.vehicle.dao.TTerminalPositionInfoDao;
import com.quartet.modules.vehicle.dto.TPositionTimeGroupByCustomerDto;
import com.quartet.modules.vehicle.dto.TTerminalPositionCountGroupByCustomerDto;
import com.quartet.utils.BinaryUtil;
import com.quartet.utils.StringUtils;
import com.quartet.utils.enums.MultimediaTypeEnum;
import com.quartet.utils.enums.PeriodTypeEnum;
import com.quartet.utils.enums.TargetTypeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.Duration;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 数据量统计信息
 *
 * @author makejava
 * @since 2021-06-20 18:55:07
 */
@RestController
@RequestMapping("TDataStatisticsController")
@Slf4j
@Api(tags = "业务：数据量统计")
public class TDataStatisticsController {

    @Autowired
    TTerminalStockDao tTerminalStockDao;

    @Autowired
    TTerminalPositionInfoDao tTerminalPositionInfoDao;

    @Autowired
    TMultimediaDao tMultimediaDao;

    @Autowired
    TCustomerInfoService tCustomerInfoService;

    /**
     * 分页查询服务统计信息
     *
     * @return 查询结果
     */
    @ApiOperation("按照客户统计各种数据量")
    @PostMapping("/queryServiceStatisticsList")
    public ApiResult<PageResult<DataStatisticsResponseDto>> queryServiceStatisticsList(@RequestBody StatisticsRequestDto statisticsRequestDto) {
        //设置开始时间
        if (ObjectUtil.isNotEmpty(statisticsRequestDto.getStartTime()) && ObjectUtil.isNotEmpty(statisticsRequestDto.getEndTime())) {

        } else if (com.quartet.modules.statistics.Enum.QueryPeriodEnum.YESTERDAY.getValue().equals(statisticsRequestDto.getQueryPeriod()) || com.quartet.modules.statistics.Enum.QueryPeriodEnum.TODAY.getValue().equals(statisticsRequestDto.getQueryPeriod())) {
            String queryPeriod = statisticsRequestDto.getQueryPeriod();
            if (StringUtils.isNotBlank(queryPeriod)) {
                com.quartet.modules.statistics.Enum.QueryPeriodEnum queryPeriodEnum = com.quartet.modules.statistics.Enum.QueryPeriodEnum.find(queryPeriod);
                queryPeriodEnum.setFilterTime(statisticsRequestDto);
            }
        } else {
            String queryPeriod = statisticsRequestDto.getQueryPeriod();
            if (StringUtils.isNotBlank(queryPeriod)) {
                com.quartet.modules.statistics.Enum.QueryPeriodEnum queryPeriodEnum = com.quartet.modules.statistics.Enum.QueryPeriodEnum.find(queryPeriod);
                queryPeriodEnum.setFilterTime(statisticsRequestDto);
            }
        }
        //查询客户接入设备数
        List<TTerminalCountGroupByCustomerDto> tTerminalCountGroupByCustomerDtoList = tTerminalStockDao.queryTerminalCountGroupCustomer(statisticsRequestDto);
        Map<String, TTerminalCountGroupByCustomerDto> stringTTerminalCountGroupByCustomerDtoMap = tTerminalCountGroupByCustomerDtoList.stream().collect(Collectors.toMap(TTerminalCountGroupByCustomerDto::getCustomerCode, item -> item));
        //查询客户平台累计数据量
        List<TTerminalPositionCountGroupByCustomerDto> tTerminalPositionCountGroupByCustomerDtoList = tTerminalPositionInfoDao.queryPositionCountGroupByCustomer(statisticsRequestDto);
        Map<String, Integer> tTerminalPositionCountGroupByCustomerDtoMap = tTerminalPositionCountGroupByCustomerDtoList.stream().collect(Collectors.toMap(TTerminalPositionCountGroupByCustomerDto::getCustomerCode, TTerminalPositionCountGroupByCustomerDto::getCount));
        //查询客户抓拍数
        List<MediaCountResponseDto> mediaSnapCountResponseDtoList = tMultimediaDao.queryMultimediaCountGroupType(statisticsRequestDto, MultimediaTypeEnum.SNAP.getValue());
        Map<String, Integer> mediaSnapCountResponseDtoMap = mediaSnapCountResponseDtoList.stream().collect(Collectors.toMap(MediaCountResponseDto::getCustomerCode, MediaCountResponseDto::getCount));
        //查询客户录音条数
        List<MediaCountResponseDto> mediaRecordingCountResponseDtoList = tMultimediaDao.queryMultimediaCountGroupType(statisticsRequestDto, MultimediaTypeEnum.RECORDING.getValue());
        Map<String, Integer> mediaRecordingCountResponseDtoMap = mediaRecordingCountResponseDtoList.stream().collect(Collectors.toMap(MediaCountResponseDto::getCustomerCode, MediaCountResponseDto::getCount));
        //查询客户录音条数
        List<MediaCountResponseDto> mediaTimeResponseDtoList = tMultimediaDao.queryMultimediaTime(statisticsRequestDto);
        Map<String, Integer> mediaTimeResponseDtoMap = mediaTimeResponseDtoList.stream().collect(Collectors.toMap(MediaCountResponseDto::getCustomerCode, MediaCountResponseDto::getTime));
        //查询客户设备运营时长
        List<TPositionTimeGroupByCustomerDto> tPositionTimeGroupByCustomerDtoList = tTerminalPositionInfoDao.queryPositionCountByType(statisticsRequestDto, BinaryUtil.convert2Binary(Lists.newArrayList(1)));
        Map<String, Integer> tPositionTimeGroupByCustomerDtoMap = tPositionTimeGroupByCustomerDtoList.stream().collect(Collectors.toMap(TPositionTimeGroupByCustomerDto::getCustomerCode, TPositionTimeGroupByCustomerDto::getTime));

        IPage<TCustomerInfo> page = new Page<>(statisticsRequestDto.getCurrent(), statisticsRequestDto.getLimit());
        QueryWrapper<TCustomerInfo> queryWrapper = new QueryWrapper<>();
        if (CollectionUtil.isNotEmpty(statisticsRequestDto.getCustomerCodeList())) {
            queryWrapper.lambda().in(TCustomerInfo::getCustomerCode, statisticsRequestDto.getCustomerCodeList());
        }
        IPage<TCustomerInfo> dbResult = tCustomerInfoService.page(page,queryWrapper);
        PageResult<DataStatisticsResponseDto> pageResult = new PageResult();
        List<DataStatisticsResponseDto> dataStatisticsResponseDtoList = dbResult.getRecords().stream().map(tCustomerInfo -> {
            DataStatisticsResponseDto dataStatisticsResponseDto = new DataStatisticsResponseDto();
            dataStatisticsResponseDto.setCustomerCode(tCustomerInfo.getCustomerCode());
            dataStatisticsResponseDto.setCustomerName(tCustomerInfo.getCustomerName());
            dataStatisticsResponseDto.setTerminalCount(Optional.ofNullable(stringTTerminalCountGroupByCustomerDtoMap.get(tCustomerInfo.getCustomerCode())).map(x -> x.getTerminalCount()).orElse(0));
            dataStatisticsResponseDto.setPlatformTotal(Optional.ofNullable(tTerminalPositionCountGroupByCustomerDtoMap.get(tCustomerInfo.getCustomerCode())).orElse(0));
            dataStatisticsResponseDto.setCaptureTotal(Optional.ofNullable(mediaSnapCountResponseDtoMap.get(tCustomerInfo.getCustomerCode())).orElse(0));
            dataStatisticsResponseDto.setRecordingsTotal(Optional.ofNullable(mediaRecordingCountResponseDtoMap.get(tCustomerInfo.getCustomerCode())).orElse(0));
            dataStatisticsResponseDto.setRecordingsTime(Optional.ofNullable(mediaTimeResponseDtoMap.get(tCustomerInfo.getCustomerCode())).orElse(0));
            dataStatisticsResponseDto.setTerminalOperationTime(Optional.ofNullable(tPositionTimeGroupByCustomerDtoMap.get(tCustomerInfo.getCustomerCode())).orElse(0));
            return dataStatisticsResponseDto;
        }).collect(Collectors.toList());
        pageResult.setTotal(dbResult.getTotal());
        pageResult.setData(dataStatisticsResponseDtoList);
        return ApiResult.ok(pageResult);
    }

    /**
     * 统计各种指标的趋势图
     *
     * @return 查询结果
     */
    @ApiOperation("统计各种指标的趋势图")
    @PostMapping("/queryServiceStatisticChart")
    public ApiResult<DataStatisticsChartResponseDto> queryServiceStatisticChart(@RequestBody DataStatisticsRequestDto dataStatisticsRequestDto) {
        List<String> axis=null;
        //处理横坐标的值和自定义时间
        if (ObjectUtil.isNotEmpty(dataStatisticsRequestDto.getStartTime()) && ObjectUtil.isNotEmpty(dataStatisticsRequestDto.getEndTime())) {
            long days = Duration.between(dataStatisticsRequestDto.getStartTime(), dataStatisticsRequestDto.getEndTime()).toDays();
            if (days > 30) {
                dataStatisticsRequestDto.setPeriodType(PeriodTypeEnum.MONTH.getValue());
                axis = com.quartet.modules.statistics.Enum.QueryPeriodEnum.getBetweenMonthAxis(dataStatisticsRequestDto.getStartTime(), dataStatisticsRequestDto.getEndTime());
            } else {
                dataStatisticsRequestDto.setPeriodType(PeriodTypeEnum.DAY.getValue());
                axis = com.quartet.modules.statistics.Enum.QueryPeriodEnum.getBetweenDayAxis(dataStatisticsRequestDto.getStartTime(), dataStatisticsRequestDto.getEndTime());
            }
        } else if (com.quartet.modules.statistics.Enum.QueryPeriodEnum.YESTERDAY.getValue().equals(dataStatisticsRequestDto.getQueryPeriod()) || com.quartet.modules.statistics.Enum.QueryPeriodEnum.TODAY.getValue().equals(dataStatisticsRequestDto.getQueryPeriod())) {
            String queryPeriod = dataStatisticsRequestDto.getQueryPeriod();
            if (StringUtils.isNotBlank(queryPeriod)) {
                com.quartet.modules.statistics.Enum.QueryPeriodEnum queryPeriodEnum = com.quartet.modules.statistics.Enum.QueryPeriodEnum.find(queryPeriod);
                queryPeriodEnum.setFilterTime(dataStatisticsRequestDto);
                axis = queryPeriodEnum.getAxis();
                dataStatisticsRequestDto.setPeriodType(PeriodTypeEnum.HOUR.getValue());
            }
        } else {
            String queryPeriod = dataStatisticsRequestDto.getQueryPeriod();
            if (StringUtils.isNotBlank(queryPeriod)) {
                com.quartet.modules.statistics.Enum.QueryPeriodEnum queryPeriodEnum = com.quartet.modules.statistics.Enum.QueryPeriodEnum.find(queryPeriod);
                queryPeriodEnum.setFilterTime(dataStatisticsRequestDto);
                axis = queryPeriodEnum.getAxis();
                dataStatisticsRequestDto.setPeriodType(PeriodTypeEnum.DAY.getValue());
            }
        }



        DataStatisticsChartResponseDto dataStatisticsChartResponseDto=new DataStatisticsChartResponseDto();
        dataStatisticsChartResponseDto.setAxis(axis);
        Map<String, Integer> map = axis.stream().collect(Collectors.toMap(s -> s, s -> 0));
        if (TargetTypeEnum.TERMINAL_COUNT.getValue().equals(dataStatisticsRequestDto.getTargetType())) {
            //统计接入设备数
            queryTerminalCountChart(dataStatisticsRequestDto,map,dataStatisticsChartResponseDto);
        } else if (TargetTypeEnum.POSITION_COUNT.getValue().equals(dataStatisticsRequestDto.getTargetType())) {
            //统计平台累积数据量
            queryPositionCountChart(dataStatisticsRequestDto,map,dataStatisticsChartResponseDto);
        } else if (TargetTypeEnum.SNAP_COUNT.getValue().equals(dataStatisticsRequestDto.getTargetType())) {
            //统计抓拍数
            querySnapCountChart(dataStatisticsRequestDto,map,dataStatisticsChartResponseDto);
        } else if (TargetTypeEnum.RECORDING_COUNT.getValue().equals(dataStatisticsRequestDto.getTargetType())) {
            //统计录音条数
            queryRecordingCountChart(dataStatisticsRequestDto,map,dataStatisticsChartResponseDto);
        } else if (TargetTypeEnum.RECORDING_TIME.getValue().equals(dataStatisticsRequestDto.getTargetType())) {
            //统计录音时长
            queryRecordingTimeChart(dataStatisticsRequestDto,map,dataStatisticsChartResponseDto);
        } else if (TargetTypeEnum.OPERATE_TIME.getValue().equals(dataStatisticsRequestDto.getTargetType())) {
            //统计设备运营时长
            queryOperateTimeChart(dataStatisticsRequestDto,map,dataStatisticsChartResponseDto);
        }else {
            return ApiResult.ok();
        }

        return ApiResult.ok(dataStatisticsChartResponseDto);
    }

    /**
     *  统计接入设备数
     * @param dataStatisticsRequestDto
     * @return
     */
    private  void queryTerminalCountChart(DataStatisticsRequestDto dataStatisticsRequestDto,Map<String,Integer> map,DataStatisticsChartResponseDto dataStatisticsChartResponseDto) {
        if (PeriodTypeEnum.HOUR.getValue().equals(dataStatisticsRequestDto.getPeriodType())){
            List<DataStatisticsGroupByTimeResponseDto> dataStatisticsGroupByTimeResponseDtoList = tTerminalStockDao.queryTerminalCountGroupTimeHour(dataStatisticsRequestDto);
            dataStatisticsGroupByTimeResponseDtoList.forEach(dataStatisticsGroupByTimeResponseDto -> {
                map.put(dataStatisticsGroupByTimeResponseDto.getCreateTime(),dataStatisticsGroupByTimeResponseDto.getCount());
            });
        }else if (PeriodTypeEnum.DAY.getValue().equals(dataStatisticsRequestDto.getPeriodType())){
            List<DataStatisticsGroupByTimeResponseDto> dataStatisticsGroupByTimeResponseDtoList = tTerminalStockDao.queryTerminalCountGroupTimeDay(dataStatisticsRequestDto);
            dataStatisticsGroupByTimeResponseDtoList.forEach(dataStatisticsGroupByTimeResponseDto -> {
                map.put(dataStatisticsGroupByTimeResponseDto.getCreateTime(),dataStatisticsGroupByTimeResponseDto.getCount());
            });
        }else {
            List<DataStatisticsGroupByTimeResponseDto> dataStatisticsGroupByTimeResponseDtoList = tTerminalStockDao.queryTerminalCountGroupTimeMonth(dataStatisticsRequestDto);
            dataStatisticsGroupByTimeResponseDtoList.forEach(dataStatisticsGroupByTimeResponseDto -> {
                map.put(dataStatisticsGroupByTimeResponseDto.getCreateTime(),dataStatisticsGroupByTimeResponseDto.getCount());
            });
        }
        dataStatisticsChartResponseDto.setValueList(new ArrayList<>(map.values()));
    }

    /**
     *  统计平台数据量
     * @param dataStatisticsRequestDto
     * @param map
     * @param dataStatisticsChartResponseDto
     */
    private void queryPositionCountChart(DataStatisticsRequestDto dataStatisticsRequestDto, Map<String, Integer> map, DataStatisticsChartResponseDto dataStatisticsChartResponseDto) {
        if (PeriodTypeEnum.HOUR.getValue().equals(dataStatisticsRequestDto.getPeriodType())){
            List<DataStatisticsGroupByTimeResponseDto> dataStatisticsGroupByTimeResponseDtoList = tTerminalPositionInfoDao.queryPositionCountGroupByTimeHour(dataStatisticsRequestDto);
            dataStatisticsGroupByTimeResponseDtoList.forEach(dataStatisticsGroupByTimeResponseDto -> {
                map.put(dataStatisticsGroupByTimeResponseDto.getCreateTime(),dataStatisticsGroupByTimeResponseDto.getCount());
            });
        }else if (PeriodTypeEnum.DAY.getValue().equals(dataStatisticsRequestDto.getPeriodType())){
            List<DataStatisticsGroupByTimeResponseDto> dataStatisticsGroupByTimeResponseDtoList = tTerminalPositionInfoDao.queryPositionCountGroupByTimeDay(dataStatisticsRequestDto);
            dataStatisticsGroupByTimeResponseDtoList.forEach(dataStatisticsGroupByTimeResponseDto -> {
                map.put(dataStatisticsGroupByTimeResponseDto.getCreateTime(),dataStatisticsGroupByTimeResponseDto.getCount());
            });
        }else {
            List<DataStatisticsGroupByTimeResponseDto> dataStatisticsGroupByTimeResponseDtoList = tTerminalPositionInfoDao.queryPositionCountGroupByTimeMonth(dataStatisticsRequestDto);
            dataStatisticsGroupByTimeResponseDtoList.forEach(dataStatisticsGroupByTimeResponseDto -> {
                map.put(dataStatisticsGroupByTimeResponseDto.getCreateTime(),dataStatisticsGroupByTimeResponseDto.getCount());
            });
        }
        dataStatisticsChartResponseDto.setValueList(new ArrayList<>(map.values()));
    }

    /**
     *  统计抓拍数
     * @param dataStatisticsRequestDto
     * @param map
     * @param dataStatisticsChartResponseDto
     */
    private void querySnapCountChart(DataStatisticsRequestDto dataStatisticsRequestDto, Map<String, Integer> map, DataStatisticsChartResponseDto dataStatisticsChartResponseDto) {
        if (PeriodTypeEnum.HOUR.getValue().equals(dataStatisticsRequestDto.getPeriodType())){
            List<DataStatisticsGroupByTimeResponseDto> dataStatisticsGroupByTimeResponseDtoList = tMultimediaDao.queryMultimediaCountGroupTimeHour(dataStatisticsRequestDto,MultimediaTypeEnum.SNAP.getValue());
            dataStatisticsGroupByTimeResponseDtoList.forEach(dataStatisticsGroupByTimeResponseDto -> {
                map.put(dataStatisticsGroupByTimeResponseDto.getCreateTime(),dataStatisticsGroupByTimeResponseDto.getCount());
            });
        }else if (PeriodTypeEnum.DAY.getValue().equals(dataStatisticsRequestDto.getPeriodType())){
            List<DataStatisticsGroupByTimeResponseDto> dataStatisticsGroupByTimeResponseDtoList = tMultimediaDao.queryMultimediaCountGroupTimeDay(dataStatisticsRequestDto,MultimediaTypeEnum.SNAP.getValue());
            dataStatisticsGroupByTimeResponseDtoList.forEach(dataStatisticsGroupByTimeResponseDto -> {
                map.put(dataStatisticsGroupByTimeResponseDto.getCreateTime(),dataStatisticsGroupByTimeResponseDto.getCount());
            });
        }else {
            List<DataStatisticsGroupByTimeResponseDto> dataStatisticsGroupByTimeResponseDtoList = tMultimediaDao.queryMultimediaCountGroupTimeMonth(dataStatisticsRequestDto,MultimediaTypeEnum.SNAP.getValue());
            dataStatisticsGroupByTimeResponseDtoList.forEach(dataStatisticsGroupByTimeResponseDto -> {
                map.put(dataStatisticsGroupByTimeResponseDto.getCreateTime(),dataStatisticsGroupByTimeResponseDto.getCount());
            });
        }
        dataStatisticsChartResponseDto.setValueList(new ArrayList<>(map.values()));
    }

    /**
     *  统计录音数
     * @param dataStatisticsRequestDto
     * @param map
     * @param dataStatisticsChartResponseDto
     */
    private void queryRecordingCountChart(DataStatisticsRequestDto dataStatisticsRequestDto, Map<String, Integer> map, DataStatisticsChartResponseDto dataStatisticsChartResponseDto) {
        if (PeriodTypeEnum.HOUR.getValue().equals(dataStatisticsRequestDto.getPeriodType())){
            List<DataStatisticsGroupByTimeResponseDto> dataStatisticsGroupByTimeResponseDtoList = tMultimediaDao.queryMultimediaCountGroupTimeHour(dataStatisticsRequestDto,MultimediaTypeEnum.RECORDING.getValue());
            dataStatisticsGroupByTimeResponseDtoList.forEach(dataStatisticsGroupByTimeResponseDto -> {
                map.put(dataStatisticsGroupByTimeResponseDto.getCreateTime(),dataStatisticsGroupByTimeResponseDto.getCount());
            });
        }else if (PeriodTypeEnum.DAY.getValue().equals(dataStatisticsRequestDto.getPeriodType())){
            List<DataStatisticsGroupByTimeResponseDto> dataStatisticsGroupByTimeResponseDtoList = tMultimediaDao.queryMultimediaCountGroupTimeDay(dataStatisticsRequestDto,MultimediaTypeEnum.RECORDING.getValue());
            dataStatisticsGroupByTimeResponseDtoList.forEach(dataStatisticsGroupByTimeResponseDto -> {
                map.put(dataStatisticsGroupByTimeResponseDto.getCreateTime(),dataStatisticsGroupByTimeResponseDto.getCount());
            });
        }else {
            List<DataStatisticsGroupByTimeResponseDto> dataStatisticsGroupByTimeResponseDtoList = tMultimediaDao.queryMultimediaCountGroupTimeMonth(dataStatisticsRequestDto,MultimediaTypeEnum.RECORDING.getValue());
            dataStatisticsGroupByTimeResponseDtoList.forEach(dataStatisticsGroupByTimeResponseDto -> {
                map.put(dataStatisticsGroupByTimeResponseDto.getCreateTime(),dataStatisticsGroupByTimeResponseDto.getCount());
            });
        }
        dataStatisticsChartResponseDto.setValueList(new ArrayList<>(map.values()));
    }

    /**
     *  统计录音时长
     * @param dataStatisticsRequestDto
     * @param map
     * @param dataStatisticsChartResponseDto
     */
    private void queryRecordingTimeChart(DataStatisticsRequestDto dataStatisticsRequestDto, Map<String, Integer> map, DataStatisticsChartResponseDto dataStatisticsChartResponseDto) {
        if (PeriodTypeEnum.HOUR.getValue().equals(dataStatisticsRequestDto.getPeriodType())){
            List<DataStatisticsGroupByTimeResponseDto> dataStatisticsGroupByTimeResponseDtoList = tMultimediaDao.queryMultimediaTimeHour(dataStatisticsRequestDto);
            dataStatisticsGroupByTimeResponseDtoList.forEach(dataStatisticsGroupByTimeResponseDto -> {
                map.put(dataStatisticsGroupByTimeResponseDto.getCreateTime(),dataStatisticsGroupByTimeResponseDto.getCount());
            });
        }else if (PeriodTypeEnum.DAY.getValue().equals(dataStatisticsRequestDto.getPeriodType())){
            List<DataStatisticsGroupByTimeResponseDto> dataStatisticsGroupByTimeResponseDtoList = tMultimediaDao.queryMultimediaTimeDay(dataStatisticsRequestDto);
            dataStatisticsGroupByTimeResponseDtoList.forEach(dataStatisticsGroupByTimeResponseDto -> {
                map.put(dataStatisticsGroupByTimeResponseDto.getCreateTime(),dataStatisticsGroupByTimeResponseDto.getCount());
            });
        }else {
            List<DataStatisticsGroupByTimeResponseDto> dataStatisticsGroupByTimeResponseDtoList = tMultimediaDao.queryMultimediaTimeMonth(dataStatisticsRequestDto);
            dataStatisticsGroupByTimeResponseDtoList.forEach(dataStatisticsGroupByTimeResponseDto -> {
                map.put(dataStatisticsGroupByTimeResponseDto.getCreateTime(),dataStatisticsGroupByTimeResponseDto.getCount());
            });
        }
        dataStatisticsChartResponseDto.setValueList(new ArrayList<>(map.values()));
    }

    /**
     *  统计设备运营时长
     * @param dataStatisticsRequestDto
     * @param map
     * @param dataStatisticsChartResponseDto
     */
    private void queryOperateTimeChart(DataStatisticsRequestDto dataStatisticsRequestDto, Map<String, Integer> map, DataStatisticsChartResponseDto dataStatisticsChartResponseDto) {
        if (PeriodTypeEnum.HOUR.getValue().equals(dataStatisticsRequestDto.getPeriodType())){
            List<DataStatisticsGroupByTimeResponseDto> dataStatisticsGroupByTimeResponseDtoList = tMultimediaDao.queryMultimediaTimeHour(dataStatisticsRequestDto);
            dataStatisticsGroupByTimeResponseDtoList.forEach(dataStatisticsGroupByTimeResponseDto -> {
                map.put(dataStatisticsGroupByTimeResponseDto.getCreateTime(),dataStatisticsGroupByTimeResponseDto.getCount());
            });
        }else if (PeriodTypeEnum.DAY.getValue().equals(dataStatisticsRequestDto.getPeriodType())){
            List<DataStatisticsGroupByTimeResponseDto> dataStatisticsGroupByTimeResponseDtoList = tMultimediaDao.queryMultimediaTimeDay(dataStatisticsRequestDto);
            dataStatisticsGroupByTimeResponseDtoList.forEach(dataStatisticsGroupByTimeResponseDto -> {
                map.put(dataStatisticsGroupByTimeResponseDto.getCreateTime(),dataStatisticsGroupByTimeResponseDto.getCount());
            });
        }else {
            List<DataStatisticsGroupByTimeResponseDto> dataStatisticsGroupByTimeResponseDtoList = tMultimediaDao.queryMultimediaTimeMonth(dataStatisticsRequestDto);
            dataStatisticsGroupByTimeResponseDtoList.forEach(dataStatisticsGroupByTimeResponseDto -> {
                map.put(dataStatisticsGroupByTimeResponseDto.getCreateTime(),dataStatisticsGroupByTimeResponseDto.getCount());
            });
        }
        dataStatisticsChartResponseDto.setValueList(new ArrayList<>(map.values()));
    }
}